package com.ruoyi.project.system.goods.img.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.goods.img.domain.GoodsImg;
import com.ruoyi.project.system.goods.img.service.IGoodsImgService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品 主图Controller
 * 
 * @author LCL
 * @date 2020-06-12
 */
@Controller
@RequestMapping("/system/img")
public class GoodsImgController extends BaseController
{
    private String prefix = "system/img";

    @Autowired
    private IGoodsImgService goodsImgService;

    @RequiresPermissions("system:img:view")
    @GetMapping()
    public String img()
    {
        return prefix + "/img";
    }

    /**
     * 查询商品 主图列表
     */
    @RequiresPermissions("system:img:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsImg goodsImg)
    {
        startPage();
        List<GoodsImg> list = goodsImgService.selectGoodsImgList(goodsImg);
        return getDataTable(list);
    }

    /**
     * 导出商品 主图列表
     */
    @RequiresPermissions("system:img:export")
    @Log(title = "商品 主图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsImg goodsImg)
    {
        List<GoodsImg> list = goodsImgService.selectGoodsImgList(goodsImg);
        ExcelUtil<GoodsImg> util = new ExcelUtil<GoodsImg>(GoodsImg.class);
        return util.exportExcel(list, "img");
    }

    /**
     * 新增商品 主图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品 主图
     */
    @RequiresPermissions("system:img:add")
    @Log(title = "商品 主图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsImg goodsImg)
    {
        return toAjax(goodsImgService.insertGoodsImg(goodsImg));
    }

    /**
     * 修改商品 主图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GoodsImg goodsImg = goodsImgService.selectGoodsImgById(id);
        mmap.put("goodsImg", goodsImg);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品 主图
     */
    @RequiresPermissions("system:img:edit")
    @Log(title = "商品 主图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsImg goodsImg)
    {
        return toAjax(goodsImgService.updateGoodsImg(goodsImg));
    }

    /**
     * 删除商品 主图
     */
    @RequiresPermissions("system:img:remove")
    @Log(title = "商品 主图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsImgService.deleteGoodsImgByIds(ids));
    }
}
